<?php
declare(strict_types=1);


namespace App\Hoenix\Mapper;

use App\Hoenix\Model\HoenixKeyword;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 搜索词列表Mapper类
 */
class HoenixKeywordMapper extends AbstractMapper
{
    /**
     * @var HoenixKeyword
     */
    public $model;

    public function assignModel()
    {
        $this->model = HoenixKeyword::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // 主键
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 
        if (isset($params['kw']) && filled($params['kw'])) {
            $query->where('kw', 'like', '%'.$params['kw'].'%');
        }

        // 次数
        if (isset($params['num']) && filled($params['num'])) {
            $query->where('num', '=', $params['num']);
        }

        return $query;
    }
}